﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Gman.Entity.Entities;
using System.Collections.Generic;
using System.Web.Mvc;
using Gman.WebApp.ServiceControllers;
using System.Text;


namespace Gman.WebApp.Models
{
    public class MaterialModelValidator : ValidationBase
    {
        public List<KeyValuePair<string, string>> Validate(MaterialModel model)
        {
            BienModelValidator validator = new BienModelValidator();
            validator.RequiredFieldValidation("Material.DescMate", model.Material.DescMate, "Nombre del Material");
            validator.RequiredFieldValidation("Material.UniMedMate", model.Material.UniMedMate, "Unidad de Medida");
            validator.RequiredFieldValidation("Material.SaldActMate", model.Material.SaldActMate, "Saldo Actual");
            validator.RequiredFieldValidation("Material.CostoPromMate", model.Material.CostoPromMate, "Costo Promedio");
            validator.RequiredFieldValidation("Material.PrecPromMate", model.Material.PrecPromMate, "PrecioPromedio");
            validator.RequiredFieldValidation("Material.StckMinMate", model.Material.StckMinMate, "Stock Minimo");
            validator.RequiredFieldValidation("Material.StckRepoMate", model.Material.StckRepoMate, "Stock Reposicion");

            return validator.ValidationList;
        }

        public static string BuildErrorMessage(List<KeyValuePair<string, string>> validationList)
        {
            StringBuilder sb = new StringBuilder(string.Empty);
            if (validationList.Count > 0)
                sb = new StringBuilder("Please fix the following error(s):");
            foreach (var validationError in validationList)
            {
                sb.Append("\n - ").Append(validationError.Value);
            }
            return sb.ToString();
        }
    }
}
